package com.muyan.sys.common.core.domain.model;





import com.muyan.sys.common.constant.HttpStatus;

import java.io.Serializable;

/**
 * 所有请求统一返回的结果信息
 */

public class SaasResult<T> implements  Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1345262189069155698L;
	//错误代码:200:成功;500:服务器异常；555：业务异常

	private int code;
	//提示信息

	private String msg;
	//结果数据

	private T data;
    
    public static <T>  SaasResult<T>  ok(String msg,T data) {
    	if(msg == null) {
    		msg ="成功";
    	}
        return  restResult(HttpStatus.SUCCESS,msg,data);
    }

	public static <T>  SaasResult<T>  result(int status,String msg,T data) {
		return  restResult(status,msg,data);
	}

    public static <T> SaasResult<T>  ok(String msg) {
        return SaasResult.ok(msg,null);
    }

	public static <T> SaasResult<T>  success(T data) {
		return SaasResult.ok("success",data);
	}

    public static <T>  SaasResult<T>  ok() {
        return SaasResult.ok(null);
    }
    public static <T> SaasResult <T>  error(String msg,T data) {
    	if(msg == null) {
    		msg ="业务异常";
    	}
        return restResult(HttpStatus.ERROR, msg, data);
    }
    public static <T> SaasResult<T>  error(String msg) {
    	
        return SaasResult.error(msg,null);
    }
	public static <T> SaasResult<T>  error(int status,String msg) {

		return SaasResult.result(status,msg,null);
	}
	public static<T>  SaasResult<T>  ok(int status,String msg,T data) {

		return SaasResult.result(status,msg,data);
	}
    public SaasResult() {
	
    }
    public static <T>  SaasResult<T>  builder(int status,String msg,T data) {
    	
        return  restResult(status,msg,data);
    }
    private static <T> SaasResult<T> restResult(int status, String msg,T data) {
        SaasResult<T> apiResult = new SaasResult<>();
        apiResult.setCode(status);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        return apiResult;
    }
	public SaasResult(int status, String msg, T data) {
		this.code = status;
		this.msg = msg;
		this.data = data;
	}


	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	
}
